import QtQuick 2.9
import QtQuick.Window 2.2

import "js/util.js" as Util
import "./qml/form"
import "qml/common"
import "./qml/form/login"

Window {
    id: m_root_id
    color:"white"
    visible: true
    property var islogin: false
    property int m_lineValue:getLineValue()
    signal quitsignal()

    onQuitsignal: {
        islogin = false
    }

    Loader{
        z:10
        id: m_main_id
        width: parent.width
        height: parent.height
    }

//    LoginPage{
//        z:10
//        id: loginpage
//        visible: !islogin
//        width: m_root_id.width
//        height: m_root_id.height
//    }

//    MainView{
//        id: mainview
//        visible: islogin
//        width: m_root_id.width
//        height: m_root_id.height
//    }

    PageStackView{
        id: m_stackView_id
        width: parent.width
        height: parent.height
        anchors.top: parent.top
        focus: true
    }

    Connections{
        target: DatabaseEngine
        onPasswordPairChanged:{
            islogin = DatabaseEngine.passwordpair   
        }
    }

    onIsloginChanged: {
        if(islogin)
            m_main_id.source = "qrc:/qml/form/MainView.qml"
        else
            m_main_id.source = "qrc:/qml/form/login/LoginPage.qml"
    }

    Component.onCompleted: {
        m_main_id.source = "qrc:/qml/form/login/LoginPage.qml"
    }

    function getLineValue(){
        return Math.min(Screen.width/7.3,Screen.height/13)
    }
}
